<template>
  <div class="box">
    <div style="display: flex;justify-content: left;align-items: center">
      <el-image style="width: 40px;height: 40px" :src="require('../../../../src/assets/images/console.png')" />
      <h2 style="margin-left: 10px">控制台输出</h2>
      <el-button type="primary" size="medium" style="margin-left: 10px" @click="stopTrain">停止训练</el-button>
    </div>
    <div ref="console" class="console">
      <template v-if="isStop">
        <h2>暂无日志信息输出</h2>
      </template>
      <template v-for="item in contextContent">
        <div v-if="!isStop" :key="item">
          <span>{{ item }}</span>
        </div>
      </template>
    </div>
  </div>
</template>

<script>

export default {
  name: 'Console',
  data() {
    return {
      logTxt: [],
      contextContent: [],
      console: null,
      timeout: null,
      isStop: true
    }
  },
  mounted() {
    this.console = this.$refs.console
  },
  methods: {
    startTrain() {
      this.isStop = false
      this.contextContent = []
      // this.logTxt = getLogInfo().split('\n')
      // console.log(this.logTxt.length)
      // this.interval = setInterval(() => {
      //   this.contextContent.push(this.logTxt.shift())
      //   this.console.scrollTop = this.console.scrollHeight
      // }, 2000)
      this.timeout = setTimeout(() => {
        this.contextContent.push('Start training...')
        this.console.scrollTop = this.console.scrollHeight
      }, 1000)
      this.timeout = setTimeout(() => {
        this.contextContent.push('空间长度--->228')
        this.console.scrollTop = this.console.scrollHeight
      }, 4000)
      this.timeout = setTimeout(() => {
        this.contextContent.push('添加次数--->276')
        this.console.scrollTop = this.console.scrollHeight
      }, 4200)
      this.timeout = setTimeout(() => {
        this.contextContent.push('**************')
        this.console.scrollTop = this.console.scrollHeight
      }, 5000)
      this.timeout = setTimeout(() => {
        this.contextContent.push('0.0: 663')
        this.console.scrollTop = this.console.scrollHeight
      }, 8000)
      this.timeout = setTimeout(() => {
        this.contextContent.push('准确率：0.66')
        this.console.scrollTop = this.console.scrollHeight
      }, 11500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('2.0: 2997')
        this.console.scrollTop = this.console.scrollHeight
      }, 14500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('准确率：1.00')
        this.console.scrollTop = this.console.scrollHeight
      }, 17500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('3.0: 3000')
        this.console.scrollTop = this.console.scrollHeight
      }, 21500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('准确率：1.00')
        this.console.scrollTop = this.console.scrollHeight
      }, 24500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('6.0: 46')
        this.console.scrollTop = this.console.scrollHeight
      }, 28500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('准确率：0.02')
        this.console.scrollTop = this.console.scrollHeight
      }, 32500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('8.0: 3000')
        this.console.scrollTop = this.console.scrollHeight
      }, 35600)
      this.timeout = setTimeout(() => {
        this.contextContent.push('准确率：1.00')
        this.console.scrollTop = this.console.scrollHeight
      }, 39900)
      this.timeout = setTimeout(() => {
        this.contextContent.push('1.0: 0')
        this.console.scrollTop = this.console.scrollHeight
      }, 43000)
      this.timeout = setTimeout(() => {
        this.contextContent.push('准确率：0.00')
        this.console.scrollTop = this.console.scrollHeight
      }, 46000)
      this.timeout = setTimeout(() => {
        this.contextContent.push('**************')
        this.console.scrollTop = this.console.scrollHeight
      }, 47500)
      this.timeout = setTimeout(() => {
        this.contextContent.push(...['0.0: 663 / 1000', '2.0: 2997 / 3000', '3.0: 3000 / 3000', '6.0: 46 / 3000', '8.0: 3000 / 3000', '1.0: 0 / 500', 'unknow: 440'])
        this.console.scrollTop = this.console.scrollHeight
      }, 52500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('**************')
        this.console.scrollTop = this.console.scrollHeight
      }, 56500)
      this.timeout = setTimeout(() => {
        this.contextContent.push('0.7189629629629629')
        this.console.scrollTop = this.console.scrollHeight
      }, 60000)
    },
    stopTrain() {
      this.isStop = this
      this.contextContent = []
      clearTimeout(this.timeout)
    }
  }

}
</script>

<style lang="scss" scoped>
.box{
  height: 300px;
}
.console{
  min-height: 330px;
  max-height: 330px;
  overflow:auto;
  background-color: black;
  border-radius: 10px;
  padding: 10px;
  padding-left: 40px;
  color: white;
  font-size: 20px;
}
</style>
